package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.ProductSpecMapper;
import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProductSpecServiceImpl implements ProductSpecService {
    @Resource
    ProductSpecMapper productSpecMapper;
    @Override
    public void deleteById(Long id) {
        productSpecMapper.deleteById(id);
    }

    @Override
    public PageInfo<ProductSpec> page(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize,true,true,null);

        return new PageInfo(productSpecMapper.selectPage());
    }

    @Override
    public void save(ProductSpec productSpec) {
        productSpec.setCreateTime(new Date());
        productSpec.setUpdateTime(new Date());
        productSpecMapper.save(productSpec);
    }

    @Override
    public void updateById(ProductSpec productSpec) {
        productSpec.setUpdateTime(new Date());
        productSpecMapper.updateById(productSpec);
    }

    @Override
    public List<ProductSpec> listAll() {

        return productSpecMapper.selectAll();
    }
}
